<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="jsp.util.ConnectionContext" %>
<%@ page import="java.sql.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
	// paginator
	String pageNum = request.getParameter("pageNum");
	if(pageNum == null){
		pageNum = "1";
	}

	int listSize = 7;
	int currentPage = Integer.parseInt(pageNum);
	int nextPage = currentPage + 1;
	int startRow = (currentPage - 1) * listSize + 1;
	int endRow = currentPage * listSize;
	int lastRow = 0;
	int i = 0;
	int num[] = {0};
	int row = startRow;
%>







<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
	<link rel=stylesheet href="form.css" type="text/css">
</head>

<body>

<div id="wrapper" style="border:1px solid #696">
	<jsp:include page="Menubar.jsp" flush="false"/>
		
		 <center>
<p></p> 
<font size='3'><b> Notice </b></font>
<p></p>             
</center>

<TABLE border="0" width="600" cellpadding="2" cellspacing="2" align="center">
	<TR>
      		<TD>
         		<hr size='1' noshade>
      		</TD>
	</TR>

	<tr>
	<td align="center">
		<select name="말머리">
			<option value="">말머리를 선택하세요</option>
			<option value="Title">제목</option>
		</select>	
		
		<input type="text" size="20">
		<input type="button" name="BTNsearch" value="Search">
	</td>
	</tr>
</TABLE>
<p>

<TABLE border="0" width="600" cellpadding="2" cellspacing="2" align="center">
<TR>
	<TD width="100" bgcolor="cccccc" align=center><font size="2"> Number</font></TD>
	<TD width="100" bgcolor="cccccc" align=center><font size="2"> Title</font></TD>
	<TD width="100" bgcolor="cccccc" align=center><font size="2"> Prof. </font></TD>
	<TD width="100" bgcolor="cccccc" align=center><font size="2"> Date </font></TD>
	<TD width="100" bgcolor="cccccc" align=center><font size="2"> Count </font></TD>	
</TR>

<%

		int numbering=1; 
		
		
	try{
		// 데이터베이스 커넥션 생성
		Connection conn = ConnectionContext.getConnection();

		// Statement 생성
		Statement stmt = conn.createStatement();
		
		// ReseltSet의 레코드 수를 lastRow 변수에 저장
		String strSQL = "SELECT count(*) FROM profnotice";
		ResultSet rs = stmt.executeQuery(strSQL);
		
		if(rs.next())
			lastRow = rs.getInt(1);
		rs.close();
		
		
		int increase_count;
		
		// ResultSet에 레코드가 존재할 때
		if(lastRow > 0) {
				strSQL = "SELECT * FROM profnotice where profNum=1";
				rs = stmt.executeQuery(strSQL);				
				for(i=1;rs.next(); i++){
					if(i >= startRow && i <=endRow){
%>
					<TR>
						<TD align=center><%=numbering%></TD>
						<%
						increase_count=rs.getInt("count");
						%>
						
						<TD align=center>
						<a href=ProfNoticeView.jsp?numbering=<%=rs.getInt("numbering")%>>
						
						<%=rs.getString("title") %>
						</a>
						</TD>
						
						
						<TD align=center><%=rs.getString("profName") %></TD>
						<TD align=center><%=rs.getDate("registerDate") %></TD>
						<TD align=center><%=rs.getInt("count") %></TD>

					</TR>
<%						row++;
						numbering++;
					}
				}
				rs.close();
//			}
			// 사용한 Statement 종료
			stmt.close();
			// 커넥션 종료
			//conn.close();
		}
		else
		{
%>
<TR>
	<TD colspan="4"> 레코드 없음 </TD>
</TR>
<%
		}

	}catch(SQLException ex){ 
%>
<TR>
	<TD colspan="4"> 에러: <%=ex %> </TD>
</TR>
<%
	}
%>

</TABLE>
<center>
<%
	if(lastRow > 0) {
		// 페이지가 넘어갈 때 넘겨줄 파라미터
		int setPage = 1;
		
		// 마지막 페이지의 번호를 저장
		int lastPage = 0;
		if(lastRow % listSize == 0)
			lastPage = lastRow / listSize;
		else
			lastPage = lastRow / listSize + 1;
		
		
		if(setPage<currentPage)
		{
%>
			<a href="memberlist.jsp?pageNum=<%=currentPage-1%>">◀</a>
<%}
		
		// 레코드 수에 따라 쪽번호를 매긴다.	
		while(setPage <= lastPage) {
			
		if(setPage != currentPage){
%>
		<a href="memberlist.jsp?pageNum=<%=setPage%>">[<%=setPage%>]</a>
<%
		}
		else{
	%>
		[<%=setPage%>]
	<% }
			setPage = setPage + 1;
		}
		
	
		// 현재 쪽번호에 따라 다음 쪽의 번호를 파라메터로 넘겨준다.
		if(lastPage > currentPage) {
%>
		<a href="memberlist.jsp?pageNum=<%=currentPage+1%>">▶</a>
<%
		}
	}
%>
</center>
	
	<script language="javascript">
	
		function buttonclick(){
			location.href="ProfNoticeWrite.jsp?profNum=1";
			
		}
	
	</script>

	<TABLE border="0" width="600" cellpadding="2" cellspacing="2" align="center">
	<tr>
		<td align="right">
			<input type="button" value="글쓰기" onclick="buttonclick()">
		</td>
	</tr>
	</TABLE>
		 
		 
		 
	</div>
</body>
</html>